import {Component, OnInit} from '@angular/core';
import {ActivityService} from "../service/activity.service";
import {Activity} from "../entity/activity";

@Component({
  moduleId: module.id,
  selector: 'my-index',
  templateUrl: 'index.component.html',
  styleUrls: ['index.component.css'],
  providers: [ActivityService]
})

export class IndexComponent implements OnInit {

  filterActivitys:Activity[];
  activities:Activity[];
  page = 1;

  constructor(private activityService: ActivityService) {
  }

  ngOnInit(): void {
    this.activityService.getActivitys(1).subscribe(activities => this.activities = activities);
  }

  pageChange(page:any){
    this.activityService.getActivitys(page).subscribe(activities => this.activities = activities);
  }

  filter(key:string) {
    if(key==="all"){
      this.filterActivitys = this.activities;
    }else{
      this.filterActivitys = this.activities.filter(value => value.theme===key);
    }
  }

}
